#include "stdio.h"
#include "sht20.h"

//没有检查检验和
short sht20_sample_temp_or_hum(uint8_t cmd)
{
	uint8_t data[2];
	unsigned short sht20_data=0;
	int rv;
//	uint8_t tran_cmd=0xF3;
	rv=I2C_Master_Transmit(0x80,&cmd,1);
	if(0!=rv)
		return -1;
	if(cmd==0xf3)
		HAL_Delay(85);
	else if(cmd==0xf5)
		HAL_Delay(29);
	rv=I2C_Master_Receive(0x81,data,sizeof(data));
	if(0!=rv)
		return -1;

	sht20_data=data[0];
	sht20_data=(sht20_data<<8);
	sht20_data+=data[1]&0xFC;
	if(cmd==0xf3)
	{
		sht20_data=(short)((-46.85+175.72*sht20_data/65536)*10);//计算
	}
	else if(cmd==0xf5)
	{
		sht20_data=(short)((-6.0+125.0*sht20_data/65536)*10);//计算
	}
	//printf("sht20_data=%d\n",sht20_data);
	return sht20_data;
}






/*
 * sht20.c
 *
 *  Created on: Apr 25, 2023
 *      Author: HP
 */



